package com.atguigu.eduservice.service.impl;

import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.mapper.EduTeacherMapper;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2021-01-27
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService {

    //1、分页查询讲师的方法
    @Override
    public HashMap<String, Object> getTeacherFrontList(Page<EduTeacher> pageTeacher) {
        QueryWrapper<EduTeacher> wrapperTeacher = new QueryWrapper<>();
        wrapperTeacher.orderByDesc("id");//条件：根据id倒序
        //把分页数据封装到pageTeacher对象
        baseMapper.selectPage(pageTeacher, wrapperTeacher);

        List<EduTeacher> records = pageTeacher.getRecords();//每页数据集合
        long current = pageTeacher.getCurrent();//当前页
        long pages = pageTeacher.getPages();//总页数
        long size = pageTeacher.getSize();//每页记录数
        long total = pageTeacher.getTotal();//总记录数
        boolean hasNext = pageTeacher.hasNext();//是否有下一页
        boolean hasPrevious = pageTeacher.hasPrevious();//是否有上一页

        //把分页集合获取出来，放到map集合
        HashMap<String, Object> map=new HashMap<>();
        map.put("items",records);//每页数据集合
        map.put("current",current);//当前页
        map.put("pages",pages);//总页数
        map.put("size",size);//每页记录数
        map.put("total",total);//总记录数
        map.put("hasNext",hasNext);//是否有下一页
        map.put("hasPrevious",hasPrevious);//是否有上一页

        //map返回
        return map;
    }
}
